

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


/*
 开发环境及调试设备：
 Xcode7或以上，iOS9或以上，iPhone6s或以上
 
 3DTouch功能主要分为两大块：主屏幕Icon上的快捷标签（Home Screen Quick Actions）； Peek（预览）和Pop（跳至预览的详细界面）
 */
//首次启动APP调用的方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
  
    
    // 创建标签的ICON图标。
    UIApplicationShortcutIcon *firstItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
    /*
     第一个参数:type,类型,一个字符串,可以随便写,到后面通过监听类型来做对应的事情
     第二个参数:标题
     第三个参数:子标题
     第四个参数:就是图标,可以自定义,也可以使用系统的
     第五个参数:就是想传出去的信息
     */
    // 创建一个标签，并配置相关属性。
    UIMutableApplicationShortcutItem *firstItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"First" localizedTitle:@"添加" localizedSubtitle:nil icon:firstItemIcon userInfo:nil];
    UIApplicationShortcutIcon *secondItemIcon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];
    UIMutableApplicationShortcutItem *secondItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"Second" localizedTitle:@"分享" localizedSubtitle:nil icon:secondItemIcon userInfo:nil];
    
    //设置图标长按时,弹出的样式
    //iconWithTypedef: 图标的类型 这里可以跳到头文件中看icon是可以自己通过图片生成的
    // 自定义创建标签的ICON图标。
    UIApplicationShortcutIcon *thirdItemIcon = [UIApplicationShortcutIcon iconWithTemplateImageName:@""];
    UIMutableApplicationShortcutItem *thirdItem = [[UIMutableApplicationShortcutItem alloc]initWithType:@"Third" localizedTitle:@"自定义" localizedSubtitle:nil icon:thirdItemIcon userInfo:nil];
    application.shortcutItems = @[firstItem,secondItem,thirdItem];
    
    return YES;
}

//监听弹窗的点击
//当程序处于close状态，或者第一次是用3DTouch启动时，会发现没有作用，只有当程序在后台的时候用3DTouch启动才有作用。这时候是因为，当程序从关闭状态启动时会调用下面的方法
//程序在后台时会调用这个方法,点开Touch会调用这个方法
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
    NSLog(@"%@", shortcutItem);
    //,使用type值来判断是哪个列表
    if ([shortcutItem.type isEqual:@"First"])
    {
        NSLog(@"执行添加事件");
        
        UIView *view=[UIView new];
        view.frame=CGRectMake(100, 100, 60, 60);
        view.backgroundColor=[UIColor redColor];
        
        [self.window addSubview:view];
    
    }
    else if([shortcutItem.type isEqual:@"Second"])
    {
        NSLog(@"执行分享的操作");
    }
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
